<template>
    <div class="hello">
        <div style="background-color: #F1F2F5;">
            <a-row :gutter="16">
                <a-col :span="8">
                    <a-card title="快捷方式">
                        <div class="short-cut-wraper card-wrap">
                            <div class="short-cut-box" v-for="(item,index) in shortCutList" :key="index">
                                <div class="icon-wrap">
                                    <a-icon type="step-backward" />
                                </div>
                                <div class="text-wrap">{{item.name}}</div>
                            </div>
                        </div>
                    </a-card>
                </a-col>
                <a-col :span="8">
                    <a-card title="待办事项" :bordered="false">
                        <div class="todo-list-wraper card-wrap">
                            <div class="todo-item" v-for="(item,index) in todoList" :key="index">
                                <div class="todo-text">
                                    {{item.name}}
                                </div>
                                <div class="todo-number">
                                    {{item.number}}
                                </div>
                            </div>
                        </div>
                    </a-card>
                </a-col>
                <a-col :span="8">
                    <a-card title="用户信息" :bordered="false">
                        <div class="user-info-wraper card-wrap">
                            <div class="user-img" :onerror="defaultImg">
                                <!-- <img :src="'https://hawk-dev-oss.oss-cn-shanghai.aliyuncs.com/' + userInfo.LogoUrl"> -->
                                <img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic2.zhimg.com%2F3640107a6318f8c5422e25170e9367e1.jpg&refer=http%3A%2F%2Fpic2.zhimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1629207914&t=db2fb80327db6c6ad3175a9430e8e7ca" alt="">
                                <div class="user-identity"> [ {{userInfo.IsAdmin? "超级管理员" : userInfo.RoleName}} ]</div>
                            </div>
                            <div class="user-info">
                                <p>
                                    <strong class="user-name">{{userInfo.UserName}}</strong>
                                </p>
                                <p>企业名称：{{userInfo.OrgName}}</p>
                                <p>到期时间：{{ExpireDateInfo}}</p>
                                <p>到期时间：{{ExpireDateInfo}}</p>
                                <p>到期时间：{{ExpireDateInfo}}</p>
                                <p>到期时间：{{ExpireDateInfo}}</p>
                                <!-- ExpireDateInfo-->
                            </div>
                        </div>
                    </a-card>
                </a-col>
            </a-row>
        </div>
        <div style="background-color: #F1F2F5;margin-top: 15px;">
            <a-row :gutter="16">
                <a-col :span="16">
                    <a-card title="数据概览">
                        <a-tabs default-active-key="1" @change="callback">
                            <a-tab-pane key="1" tab="今日销售数据">
                                <div class="saleReportChart1 chart-stand"></div>
                            </a-tab-pane>
                            <a-tab-pane key="2" tab="最近7天销售统计" force-render>
                                <div class="saleReportChart2 chart-stand"></div>
                            </a-tab-pane>
                            <a-tab-pane key="3" tab="最近30天销售统计">
                                <div class="saleReportChart3 chart-stand"></div>
                            </a-tab-pane>
                        </a-tabs>

                    </a-card>
                </a-col>

                <a-col :span="8">
                    <a-card hoverable style="width: 300px">
                        <img slot="cover" alt="example"
                            src="https://gw.alipayobjects.com/zos/rmsportal/JiqGstEfoWAOHiTxclqi.png" />
                        <template slot="actions" class="ant-card-actions">
                            <a-icon key="setting" type="setting" />
                            <a-icon key="edit" type="edit" />
                            <a-icon key="ellipsis" type="ellipsis" />
                        </template>
                        <a-card-meta title="Card title" description="This is the description">
                            <a-avatar slot="avatar"
                                src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png" />
                        </a-card-meta>
                    </a-card>
                </a-col>
            </a-row>

            <div class="convince-wrap"> </div>
        </div>
    </div>
</template>

<script>
    export default {
        name: 'workbord',
        data() {
            return {
                formLayout: 'horizontal',
                ExpireDateInfo: '',
                form: this.$form.createForm(this, { name: 'coordinated' }),
                shortCutList: [
                    { name: '销售开单', url: 'sale', iconfont: 'sale' },
                    { name: '零售开单', url: 'sale', iconfont: 'sale' },
                    { name: '进货入库', url: 'sale', iconfont: 'sale' },
                    { name: '新增商品', url: 'sale', iconfont: 'sale' },
                    { name: '应收应付', url: 'sale', iconfont: 'sale' },
                    { name: '销售订单', url: 'sale', iconfont: 'sale' },
                    { name: '库存查询', url: 'sale', iconfont: 'sale' },
                    { name: '销售报表', url: 'sale', iconfont: 'sale' },
                ],
                todoList: [
                    { name: '待结算销售单', url: 'sale', iconfont: 'sale', number: 0 },
                    { name: '待出库订单', url: 'sale', iconfont: 'sale', number: 0 },
                    { name: '待结算销退单', url: 'sale', iconfont: 'sale', number: 0 },
                    { name: '待结算进货单', url: 'sale', iconfont: 'sale', number: 0 },
                ],
                userInfo: JSON.parse(localStorage.getItem('userInfo')) || {},
                timer: null,
                saleReportChart: null,
                defaultImg: 'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3753060787,915591864&fm=26&gp=0.jpg'
            }
        },
        methods: {
            handleSubmit(e) {
                e.preventDefault();
                this.form.validateFields((err, values) => {
                    if (!err) {
                        console.log('Received values of form: ', values);
                    }
                });
            },

            handleSelectChange(value) {
                console.log(value);
                this.form.setFieldsValue({
                    note: `Hi, ${value === 'male' ? 'man' : 'lady'}!`,
                });
            },

            async getTodoList() {
                try {
                    const res = await this.rq.requests.get('FirstPageStatistics/GetBillCntsOfWaitSettle');
                    this.todoList[0].number = res.Value.SaleCnts;
                    this.todoList[1].number = res.Value.SaleOutInvtCnts;
                    this.todoList[2].number = res.Value.SaleReturnCnts;
                    this.todoList[3].number = res.Value.PurchaseInCnts;
                } catch (error) {
                    console.log(error);
                }
            },

            async getEndTime() {
                try {
                    const res = await this.rq.requests.get('Company/GetExpireDate');
                    let time = res.Value;
                    time = time.replaceAll('/', '-');
                    this.ExpireDateInfo = time;
                } catch (error) {
                    console.log(error);
                }
            },

            drawLine(data) {
                this.saleReportChart = this.$echarts.init(document.querySelector('.saleReportChart1'));
                const options = {
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data: data.xData
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [{
                        data: data.yData,
                        type: 'line',
                        areaStyle: { color: '#DBFAFF' }, //覆盖区域颜色
                        itemStyle: {
                            normal: {
                                lineStyle: {
                                    color: '#4170A0' // 线条颜色
                                }
                            }
                        },
                        // symbol: 'star',//拐点样式
                        symbolSize: 8,//拐点大小
                    }]
                }
                this.saleReportChart.setOption(options);
            },

            async getReportData() {
                const params = {
                    BeginDate: new Date([...Array(7).keys()].map(days => new Date(Date.now() - 86400000 * days))[6]),
                    EndDate: new Date()
                }
                try {
                    const res = await this.rq.requests.get('Report/GetSaleStatistics', { params });
                    if (res.Code !== 0) {
                        this.$message.error('This is a normal message');
                        return;
                    }
                    const chartData = {
                        xData: [],
                        yData: []
                    };
                    Object.keys(res.Value).forEach(item => {
                        chartData.xData.push(item);
                        chartData.yData.push(res.Value[item]);
                    })
                    this.drawLine(chartData);
                } catch (error) {
                    console.log(error);
                }
            },

            callback(key) {
                console.log(key);
            },
        },
        mounted() {
            // this.getTodoList();
            // this.getEndTime();
            // this.drawLine();
            // this.getReportData();
            window.onresize = () => {
                clearTimeout(this.timer)
                // this.timer = setTimeout(() => {
                //     this.saleReportChart.resize();
                // }, 300)
            };
        },
    }
</script>

<style lang="less" scoped>
    .card-wrap {
        height: 250px;
    }

    .part3 {
        height: 385px;
    }

    .short-cut-wraper {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;

        .short-cut-box {
            margin-top: 15px;
            width: 23%;
            cursor: pointer;

            .icon-wrap {
                background-color: #F8F8F8;
                text-align: center;
                padding: 20px;
            }

            .text-wrap {
                text-align: center;
                padding: 4px 0;
            }

        }

        /deep/ .ant-card-body {
            padding: 15px;
        }
    }

    .todo-list-wraper {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;

        .todo-item {
            margin-bottom: 12px;
            width: 48%;
            padding: 10px 15px;
            background-color: #f8f8f8;
            color: #999;
            border-radius: 2px;
            transition: all .3s;
            -webkit-transition: all .3s;

            .todo-text {
                padding-bottom: 10px;
                font-size: 12px;
            }

            .todo-number {
                font-style: normal;
                font-size: 30px;
                font-weight: 600;
                color: #1890ff;
            }
        }
    }

    .user-info-wraper {
        display: flex;
        justify-content: space-between;

        .user-img {

            img {
                width: 150px;
                height: 150px;
                border-radius: 50%;
            }

            .user-identity {
                color: #F59023;
                margin-top: 30px;
                text-align: center;
                font-weight: bold;
            }

        }

        .user-info {
            margin-left: 22px;
        }
    }

    .chart-stand {
        width: 100%;
        height: 400px;
    }

    .box {
        background-color: #ffffff;
        margin-top: 20px;
        border-radius: 2px;
        display: flex;


        .content-title {
            color: rgba(51, 51, 51, 1);
            font-size: 16px;
            font-family: PingFangSC-Semibold;
            font-weight: bold;
        }

        .convince-wrap {
            height: 200px;
            width: 66%;
            border-right: 10px solid #F1F2F5;
        }

        .warning-wrap {
            height: 100%;
            width: 33%;
            border-left: 10px solid #F1F2F5;
        }

        .database-wrap {
            height: 100%;
            width: 66%;
            border-right: 10px solid #F1F2F5;
        }

        .sys-wrap {
            height: 100%;
            width: 33%;
            border-left: 10px solid #F1F2F5;
        }
    }
</style>